<?php
session_start(); 
include("include/db_connect.php"); 
connect();
$sql="SET CHARACTER SET UTF8";   
query($sql); 
include "try_session_login.php";
if($_GET['action']=='active'){

	switch($_GET[status]){

		case"online";
			$data=array("active"=>(0),);	
			update("tb_membership",$data,"id=$_GET[id]");
		break;
			case"offline";
			$data=array("active"=>(1),);
			update("tb_membership",$data,"id=$_GET[id]");
		break;
	}
	
}
if($_POST['action']=='benefi'){
	if($_POST['ref_id']=='' or $_POST['reward']==''){
		echo 'ใส่ข้อมูลไม่ครบถ้วน';
		exit();
	}
	if(is_numeric($_POST['reward'])==FALSE){
		echo "ค่าคอมฯต้องเป้นตัวเลขเท่านั้น";
		exit();
	}
	$data = array(
		'ref_id'=>$_POST['ref_id'],
		'membership_id'=>$_POST['id'],
		'reward'=>$_POST['reward']
	);
	if(!insert('tb_benefi',$data)){
		echo "ข้อมูลไม่ถูกต้อง";	
	}
}

if($_GET['action']=='delete_benefi'){
	delete('tb_benefi',"id='".$_GET['id']."'");
}
if($_GET['action']=='delete_member'){
	delete('tb_membership',"id='".$_GET['id']."'");
}

if($_GET['action']=='inquiry_active'){
	switch($_GET[status]){

		case"online";
			$data=array("active"=>(0),);	
			update("tb_firstclass",$data,"id=$_GET[id]");
		break;
			case"offline";
			$data=array("active"=>(1),);
			update("tb_firstclass",$data,"id=$_GET[id]");
		break;
	}
	
}

if($_GET['action']=="delete_inquiry"){
	delete('tb_firstclass',"id='".$_GET['id']."'");	
}

if($_GET['action']=='order_active'){
	switch($_GET[status]){

		case"online";
			$data=array("active"=>(0),);	
			update("tb_order",$data,"id=$_GET[id]");
		break;
			case"offline";
			$data=array("active"=>(1),);
			update("tb_order",$data,"id=$_GET[id]");
		break;
	}
	
}
if($_GET['action']=="delete_order"){
	delete('tb_order',"id='".$_GET['id']."'");	
}

if($_GET['action']=="delete_insure"){
	delete('tb_insure',"id='".$_GET['id']."'");	
}

if($_GET['action']=="add_center"){
	$data=array("center_id"=>$_GET['cid']);
	update('tb_membership',$data,"id = '".$_GET['id']."'");
}

if($_GET['action']=="delete_center"){
	$data=array("center_id"=>'');
	update('tb_membership',$data,"id = '".$_GET['id']."'");
}
if($_GET['comission']<>''){
	$data=array("center_reward"=>$_GET['comission']);
	update('tb_membership',$data,"id = '".$_GET['id']."'");
}
?>